import { requestClient } from '#/api/request';

export namespace AuthApi {
  /** 登录接口参数 */
  export interface LoginParams {
    username: string;
    password: string;
  }

  /** 登录接口返回值 */
  export interface LoginResult {
    access_token: string;
    refresh_token: string;
    user: {
      auth_provider: number;
      avatar: string;
      created_at: string;
      email: string;
      id: string;
      last_login: string;
      name: string;
      username: string;
    };
  }

  /** username注册接口返回值 */
  export interface registerResult {
    code: string;
    err: string;
    desc: string;
  }

    /** 重置密码接口参数 */
    export interface ResetPasswordParams {
      password: string;
    }
}

/**
 * 登录
 */
export async function loginApi(data: AuthApi.LoginParams) {
  return requestClient.post<AuthApi.LoginResult>('/uctoo/auth/login', data);
}

/**
 * 注册
 */
export async function registerApi(data: AuthApi.LoginParams) {
  return requestClient.post<AuthApi.registerResult>('/uctoo/auth/signup', data);
}
/**
 * 重置密码接口
 */
export async function resetPasswordApi(data: AuthApi.ResetPasswordParams) {
  return requestClient.post<AuthApi.registerResult>('/uctoo/auth/resetpassword', data);
}
/**
 * 获取用户权限码
 */
export async function getAccessCodesApi() {
  return requestClient.get<string[]>('/uctoo/auth/codes');
}
